package com.xgpush;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.IntentFilter;
import android.util.Log;

import com.tencent.android.tpush.XGIOperateCallback;
import com.tencent.android.tpush.XGPushConfig;
import com.tencent.android.tpush.XGPushManager;

// import com.tencent.android.otherPush.StubAppUtils;

public class TPushManager {

    private static BroadcastReceiver receiver = null;

    public static void init(Context context, boolean enableDebug){
        XGPushConfig.enableDebug(context, enableDebug);
        XGPushConfig.enableOtherPush(context, false);
        XGPushManager.registerPush(context);
    }

    public static void init(Context context, boolean enableDebug, boolean enableOtherPush, boolean huaweiDebug, String miPushAppId, String miPushAppKey, String mzPushAppId, String mzPushAppKey){
        XGPushConfig.enableDebug(context, enableDebug);
        XGPushConfig.enableOtherPush(context, enableOtherPush);
        XGPushConfig.setHuaweiDebug(huaweiDebug);
        XGPushConfig.setMiPushAppId(context, miPushAppId);
        XGPushConfig.setMiPushAppKey(context, miPushAppKey);
        XGPushConfig.setMzPushAppId(context, mzPushAppId);
        XGPushConfig.setMzPushAppKey(context, mzPushAppKey);
        XGPushManager.registerPush(context,new XGIOperateCallback() {
            @Override
            public void onSuccess(Object data, int flag) {
                Log.d("TPush", "注册成功，设备token为：" + data);
            }
            @Override
            public void onFail(Object data, int errCode, String msg) {
                Log.d("TPush", "注册失败，错误码：" + errCode + ",错误信息：" + msg);
            }
        });
    }

    public static BroadcastReceiver getReceiver(){
        if(null == receiver){
            receiver = new TPushModule.TPushReceiver();
        }
        return receiver;
    }

    public static IntentFilter getIntentFilter(){
        IntentFilter intentFilter = new IntentFilter();

        intentFilter.addAction("com.tencent.android.tpush.action.PUSH_MESSAGE");
        intentFilter.addAction("com.tencent.android.tpush.action.FEEDBACK");

        return intentFilter;
    }

    public static void registerReceiver(Context context){

        context.registerReceiver(getReceiver(), getIntentFilter());
    }

    public static void unregisterReceiver(Context context){
        context.unregisterReceiver(getReceiver());
    }

    // public static void attachBaseContext(Context context){
    //     StubAppUtils.attachBaseContext(context);
    // }
}
